<?php
/*	Created by Alexander Alexandrov aka SS
			hazg@mail.ru				*/
define('SSLIB_FileUpload', TRUE);

class FileUpload
{
	private $tmpname;
	function FileUpload()
	{
	}
	function SaveTemp()
	{
		
		$this->tmpname = Sslib::CiteRoot().'tmp/'.RandomKey();
		
		if(!isset($_FILES['userfile']))
			throw new Err(__T('missing uploaded file'));
		if(!isset($_FILES['userfile']['tmp_name']) || empty($_FILES['userfile']['tmp_name']))
			throw new Err(__T('missing temporary file'));
		if(move_uploaded_file($_FILES['userfile']['tmp_name'], $this->tmpname) === FALSE)
			throw new Err("cannot move file from temp");
		return $this->tmpname;
	}
	function __destruct()
	{
		/*if(isset($this->tmpname) && is_file($this->tmpname))
			unlink($this->tmpname);*/
	}
	
}